home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 2D / MacGamma / Test Main.cp < prev   
Encoding:
Text File  |  2000-09-28  |  3.6 KB  |  135 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Test Main.cp
  3.  
  4.     Contains:    Mac OS gamma test harness
  5.  
  6.     Written by:    Geoff Stahl (ggs)
  7.  
  8.     Copyright:    Copyright © 1999 Apple Computer, Inc., All Rights Reserved
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <5>     8/25/99    ggs     Added Gestalt for color QD
  13.          <4>     8/25/99    ggs     Tested changes in MacGamma code
  14.          <3>     5/20/99    ggs     Increased randomness
  15.          <2>     5/20/99    ggs     Modified demo to be something at least a little intersting and
  16.                                     to utilize the new get/restore functions
  17.          <1>     5/20/99    ggs     Initial Add
  18.  
  19.     Disclaimer:    You may incorporate this sample code into your applications without
  20.                 restriction, though the sample code has been provided "AS IS" and the
  21.                 responsibility for its operation is 100% yours.  However, what you are
  22.                 not permitted to do is to redistribute the source as "DSC Sample Code"
  23.                 after having made changes. If you're going to re-distribute the source,
  24.                 we require that you make it clear in the source that the code was
  25.                 descended from Apple Sample Code, but that you've made changes.
  26.  
  27. */
  28.  
  29.  
  30. #include <Types.h>
  31. #include <Gestalt.h>
  32. #include <Memory.h>
  33. #include <Quickdraw.h>
  34. #include <Fonts.h>
  35. #include <Events.h>
  36. #include <Menus.h>
  37. #include <Windows.h>
  38. #include <TextEdit.h>
  39. #include <Dialogs.h>
  40. #include <OSUtils.h>
  41. #include <ToolUtils.h>
  42. #include <SegLoad.h>
  43. #include <Sound.h>
  44.  
  45. #include "MacGamma.h"
  46.  
  47. /* Prototypes */
  48. void Initialize(void);
  49.  
  50. int main(void)
  51. {
  52.     Initialize();
  53.     
  54.     Ptr pGammaSave = GetSystemGammas ();
  55.  
  56.     short x [3], y [3];
  57.     short devCount = 0;
  58.     GDHandle hGDevice = GetDeviceList ();                        // top of device list
  59.     do                                                            // iterate
  60.     {
  61.         hGDevice = GetNextDevice (hGDevice);                    // next device
  62.         devCount++;
  63.     } while (hGDevice);
  64.     
  65.     short devices = devCount;
  66.     short entries = devices * 3 * 256;
  67.     unsigned char * pOrigRamp = (unsigned char * ) NewPtr (entries);
  68.     unsigned char * pRamp = (unsigned char * ) NewPtr (entries);
  69.  
  70.     devCount = 0;
  71.     hGDevice = GetDeviceList ();                                // top of device list
  72.     do                                                            // iterate
  73.     {
  74.         GetDeviceGammaRampGD (hGDevice, (Ptr)(pOrigRamp + devCount * 3 * 256));            // retrieves the gamma ramp from a graphics device (pRamp: 3 arrays of 256 elements each)
  75.         hGDevice = GetNextDevice (hGDevice);                    // next device
  76.         devCount++;
  77.     } while (hGDevice);
  78.     
  79.     for (short j = 0; j < 3; j++)
  80.     {
  81.         x [j] = (TickCount () + j * 120) % 256;
  82.         y [j] = 255;
  83.     }
  84.     
  85.     do {
  86.         for (short i = 0; i < 256 ; i++)
  87.             for (short j = 0; j < 3; j++)
  88.                 for (short k = 0; k < devices; k++)
  89.                     *(pRamp + k * 3 * 256 + j * 256 + i) = *(pOrigRamp + k * 3 * 256 + j * 256 + i) * (y [j] % 256) / 256;
  90.  
  91.         devCount = 0;
  92.         hGDevice = GetDeviceList ();                                // top of device list
  93.         do                                                            // iterate
  94.         {
  95.             SetDeviceGammaRampGD (hGDevice, (Ptr)(pRamp + devCount * 3 * 256));
  96.             hGDevice = GetNextDevice (hGDevice);                    // next device
  97.             devCount++;
  98.         } while (hGDevice);
  99.         for (short j = 0; j < 3; j++)
  100.         {
  101.             (x [j] > y [j]) ? y [j]++ : y [j]--;
  102.             if (x [j] == y [j])
  103.                 x [j] = ((TickCount () % (1457 * j)) + j * 97) % 256;
  104.         }
  105.     } while (!Button());
  106.     
  107.     RestoreSystemGammas (pGammaSave);
  108.     DisposeSystemGammas (&pGammaSave);
  109.  
  110.     return 0;    
  111. }
  112.  
  113. void Initialize(void)
  114. {
  115.     OSErr err;
  116.     long response = 0;
  117.     
  118.     MaxApplZone ();
  119.     
  120.     err = Gestalt (gestaltQuickdrawFeatures, &response);
  121.     if ((noErr != err ) || !((1 << gestaltHasColor) & response))
  122.     {
  123.         SysBeep(30);
  124.         ExitToShell();                    /* If no color QD, we must leave. */
  125.     }
  126.     
  127.     /* Initialize all the needed managers. */
  128.     InitGraf(&qd.thePort);
  129.     InitFonts();
  130.     InitWindows();
  131.     InitMenus();
  132.     TEInit();
  133.     InitDialogs(nil);
  134.     InitCursor();
  135. }